<template>
  <div>
    <div id="razz" class="cover">
      <main>
        <h1><b>教</b><b>考</b><b>分</b><b>离</b><b>系</b><b>统</b>
          <b>E</b><b>X</b><b>A</b><b>M</b><b> </b><b> </b>
          <b>S</b><b>Y</b><b>S</b><b>T</b><b>E</b><b>M</b>
        </h1>
      </main>
      <div>Copyright (c) 2022 by Carter Lovelace</div>
    </div>
    <div class="login">
      <div class="title">登录</div>
      <div class="text">
        <input class="input" type="text" placeholder="账号" ref="id">
      </div>
      <div class="text">
        <input class="input" type="password" placeholder="密码" ref="password">
      </div>
      <div class="text">
        <input class="input" type="text" placeholder="验证码" ref="captcha">
        <img style="margin-top: 10px" :src="imageSrc" @click="getCaptcha">
      </div>
      <el-button round style="margin-top: 50px" @click="login">登录</el-button>
    </div>
  </div>
</template>

<script>
import {adminLogin, getCaptcha} from '../../api/login'
export default {
  name: 'AdminLogin',
  data () {
    return {
      userInfo: {
        id: null,
        password: null
      },
      imageSrc: ''
    }
  },
  mounted () {
    this.getCaptcha()
  },
  methods: {
    getCaptcha () {
      getCaptcha(new Date() * 1).then(res => {
        console.log(res)
        this.imageSrc = window.URL.createObjectURL(res.data)
      })
    },
    login () {
      let that = this
      that.userInfo.id = that.$refs.id.value
      that.userInfo.password = that.$refs.password.value
      that.userInfo.captcha = that.$refs.captcha.value
      adminLogin(that.userInfo)
        .then(res => {
          console.log(res)
          if (res.status === 200) {
            sessionStorage.setItem('token', res.data)
            that.$router.push('/admin/questionBankManage')
          } else {
            that.$message.error(res)
          }
        })
    },
    findRandom (n) {
      return (1 + parseInt(Math.random() * 100)) % n
    },

    razz () {
      var cover = document.getElementById('razz')
      var letter = cover.getElementsByTagName('b')

      let C = ''
      let z
      z = this.findRandom(5)
      if (z === 0) {
        C = 'l-shadow'
      } else if (z === 1) {
        C = 'l-slide'
      } else if (z === 2) {
        C = 'l-spin'
      } else if (z === 3) {
        C = 'l-bump'
      } else if (z === 4) {
        C = 'l-spin-back'
      }

      let x = this.findRandom(10)
      letter[x].classList.add(C)

      setTimeout(function () {
        letter[x].classList.remove(C)
      }, 1200)

      setTimeout(function () {
        this.razz()
      }, 3000)
    }

  }
}
</script>

<style scoped>
  @import url("https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;500;700&display=swap");

  @import url("https://use.typekit.net/pez6jlf.css");

  * {
    box-sizing: border-box;
  }

  body {
    background: #232323;
    margin: 0;
    padding: 0;
    display: grid;
    min-height: 100vh;
    align-content: center;
  }

  .login {
    width: 25%;
    height: 100vmin;
    float: right;

    background: #ffffff;
  }

  .login .title {
    font-size: 30px;
    margin-top: 100px;
    margin-bottom: 100px;
  }

  .login .text {
    margin: 30px auto;
    width: 300px;
    height: 60px;
    background: #e8e8e8;

    border-radius: 30px;
  }
  .login .text .input{
    margin: 0 auto;
    font-size: 15px;
    width: 80%;
    height: 100%;
    background: transparent;

    border: none;
    outline:none;
  }

  .cover {
    float: left;
    display: grid;
    align-content: center;
    font-size: 2vmin;
    background: #f0f6ff;
    margin: 0;
    width: 75%;
    height: 100vmin;
    color: gray;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 1vmin 2.5vmin 1vmin rgba(0, 0, 0, 0.5);
  }

  .cover main {
    font-family: "arponasans", "Sequel Sans", "arial", sans-serif;
  }

  .cover h1 {
    display: grid;
    grid-template-columns: 16.6% 16.6% 16.6% 16.6% 16.6% 16.6%;
    text-align: center;
    font-size: 8vmin;
    width: 800px;
    margin: 0 auto;
    line-height: 1.65em;
    cursor: default;
  }

  .cover h1 b {
    font-weight: 500;
    -webkit-transition: all 0.4s ease;
    transition: all 0.4s ease;
    -webkit-transition-delay: 0.5s;
    transition-delay: 0.5s;
    text-shadow: 0 0;
  }

  .cover h1,
  .cover h1 b:hover {
    text-shadow: 0.05em 0.05em 0 yellow,
    0.1em 0.1em 0 orange,
    0.15em 0.15em 0 red,
    0.2em 0.2em 0 gray;
    -webkit-transform: translate(-0.2em, -0.2em);
    transform: translate(-0.2em, -0.2em);
  }

  .cover h1 b:hover {
    -webkit-transition-delay: 0s;
    transition-delay: 0s;
  }

  .cover h1 em {
    display: block;
    font-style: normal;
    width: max-content;
    font-weight: 500;
    font-size: 0.325em;
    letter-spacing: 0.35em;
    line-height: 3.75em;
    position: relative;
    grid-column: 2 / span 2;
    margin-left: 0.5em;
  }

  .cover aside {
    position: absolute;
    right: 0;
    top: 7%;
  }

  .cover aside ul {
    margin: 1vmin 0;
    padding: 0;
    list-style: none;
    z-index: 2;
  }

  .cover aside ul li {
    width: 1vmin;
    height: 2vmin;
    border: 0.25vmin solid;
    border-right: none;
    margin-bottom: -0.25vmin;
    position: relative;
  }

  .cover aside ul li::before {
    content: ":";
    font-weight: bold;
    position: absolute;
    top: 0;
    left: 0;
    text-align: right;
    width: 0.85vmin;
    height: 2vmin;
    line-height: 1.5vmin;
    font-size: 0.75em;
  }

  .cover aside ul li:first-of-type::before {
    content: "·";
  }

  .cover aside p {
    font-family: "Roboto Mono", monospace;
    position: absolute;
    right: 1.75vmin;
    top: 1vmin;
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    font-size: 0.55em;
    font-weight: 500;
    margin: 0;
  }

</style>
